package com.cyurs.netty.nio;

import java.nio.ByteBuffer;

/**
 * @Author: Cyrus
 * @CreateDate: 2020/11/16
 */
public class BufferReadOnlyDemo {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(64);

        for (int i = 0; i < 64; i++) {
            buffer.put((byte) i);
        }

        buffer.flip();

        ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();

        while (readOnlyBuffer.hasRemaining()) {
            System.out.println(readOnlyBuffer.get());
        }

        readOnlyBuffer.put((byte) 100);

    }
}
